home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 May / CMCD0504.ISO / Software / Freeware / Programare / gdiplusdelphi / demos / Special / Using DriverString / GDITEST18.dpr
Encoding:
Text File  |  2003-10-15  |  3.3 KB  |  114 lines

  1. program GDITEST18;
  2.  
  3. uses
  4.   Windows,
  5.   Messages,
  6.   SysUtils,
  7.   GDIPAPI,
  8.   GDIPOBJ;
  9.  
  10. // The following example defines three ranges of character positions within a
  11. // string and sets those ranges in a StringFormat object. Next, the
  12. // TGraphics.MeasureCharacterRanges method is used to get the three regions of
  13. // the display that are occupied by the characters that are specified by the
  14. // ranges. This is done for three different layout rectangles to show how the
  15. // regions change according to the layout of the string. Also, on the third
  16. // repetition, the string format flags are changed so that the regions measured
  17. // will include trailing spaces.
  18.  
  19. Procedure OnPaint(DC: HDC);
  20. var
  21.   graphics : TGPGraphics;
  22.   Pen: TGPPen;
  23.   Font: TGPFont;
  24.   brush: TGPSolidBrush;
  25.   Bound: TGPRECTF;
  26. const positions: array[0..3] of TGPPointF =
  27.   ((x: 100.0; y: 150.0),
  28.    (x: 150.0; y: 200.0),
  29.    (x: 300.0; y: 150.0),
  30.    (x: 150.0; y: 100.0));
  31. begin
  32.   graphics := TGPGraphics.Create(dc);
  33.   brush:= TGPSolidBrush.Create(aclBlack);
  34.   Pen:= TGPPen.Create(brush);
  35.   Font:= TGPFont.Create('Arial',16);
  36.  
  37.   graphics.MeasureDriverString(PUINT16(StringToOleStr('ABCD')), -1, Font, @positions, DriverStringOptionsCmapLookup, nil, Bound);
  38.   graphics.DrawRectangle(pen,bound);
  39.   graphics.DrawDriverString(PUINT16(StringToOleStr('ABCD')), -1, Font, brush, @positions, DriverStringOptionsCmapLookup, nil);
  40.  
  41.   brush.Free;
  42.   Font.Free;
  43.   Pen.Free;
  44.   graphics.Free;
  45. end;
  46.  
  47.  
  48.  
  49. function WndProc(Wnd : HWND; message : UINT; wParam : Integer; lParam: Integer) : Integer; stdcall;
  50. var
  51.   Handle: HDC;
  52.   ps: PAINTSTRUCT;
  53. begin
  54.   case message of
  55.     WM_PAINT:
  56.       begin
  57.         Handle := BeginPaint(Wnd, ps);
  58.         OnPaint(Handle);
  59.         EndPaint(Wnd, ps);
  60.         result := 0;
  61.       end;
  62.  
  63.     WM_DESTROY:
  64.       begin
  65.         PostQuitMessage(0);
  66.         result := 0;
  67.       end;
  68.  
  69.    else
  70.       result := DefWindowProc(Wnd, message, wParam, lParam);
  71.    end;
  72. end;
  73.  
  74. var
  75.   hWnd     : THandle;
  76.   Msg      : TMsg;
  77.   wndClass : TWndClass;
  78. begin
  79.    wndClass.style          := CS_HREDRAW or CS_VREDRAW;
  80.    wndClass.lpfnWndProc    := @WndProc;
  81.    wndClass.cbClsExtra     := 0;
  82.    wndClass.cbWndExtra     := 0;
  83.    wndClass.hInstance      := hInstance;
  84.    wndClass.hIcon          := LoadIcon(0, IDI_APPLICATION);
  85.    wndClass.hCursor        := LoadCursor(0, IDC_ARROW);
  86.    wndClass.hbrBackground  := HBRUSH(GetStockObject(WHITE_BRUSH));
  87.    wndClass.lpszMenuName   := nil;
  88.    wndClass.lpszClassName  := 'GettingStarted';
  89.  
  90.    RegisterClass(wndClass);
  91.  
  92.    hWnd := CreateWindow(
  93.       'GettingStarted',       // window class name
  94.       'Using DriverString',// window caption
  95.       WS_OVERLAPPEDWINDOW,    // window style
  96.       Integer(CW_USEDEFAULT), // initial x position
  97.       Integer(CW_USEDEFAULT), // initial y position
  98.       Integer(CW_USEDEFAULT), // initial x size
  99.       Integer(CW_USEDEFAULT), // initial y size
  100.       0,                      // parent window handle
  101.       0,                      // window menu handle
  102.       hInstance,              // program instance handle
  103.       nil);                   // creation parameters
  104.  
  105.    ShowWindow(hWnd, SW_SHOW);
  106.    UpdateWindow(hWnd);
  107.  
  108.    while(GetMessage(msg, 0, 0, 0)) do
  109.    begin
  110.       TranslateMessage(msg);
  111.       DispatchMessage(msg);
  112.    end;
  113. end.
  114.